package com.sf.web.intercptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CheckLoginIntercptor implements HandlerInterceptor {

    /**
     * 前置拦截: 登录校验
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 判断session 当中是否有信息
        Object user = request.getSession().getAttribute("USER_IN_SESSION");
        if(user == null){
            response.sendRedirect("/login.jsp");
            return false;  //进行拦截
        }
        return true;
    }
}
